from flask import Flask
import os

app = Flask(__name__)
app.config['SECRET_KEY'] = 'smartlearn_secret_key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///smartlearn.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

# 创建数据库实例
from extensions import db
db.init_app(app)

# 导入模型和路由 (在app和db创建后导入)
with app.app_context():
    from models import User, Student, Teacher, Course, LearningPath, Exercise, StudentExercise, Recommendation
    from routes import register_routes
    
    # 注册路由
    register_routes(app)
    
    # 创建数据库
    @app.before_first_request
    def create_tables():
        db.create_all()

# 上下文处理器，提供当前年份给模板
@app.context_processor
def inject_now():
    from datetime import datetime
    return {'now': datetime.utcnow()}

if __name__ == '__main__':
    app.run(debug=True) 